<?php
/**
 * 
 * Enter description here ...
 * @author 4-PC
 *
 */
class MainController extends Controller
{
	public $defaultAction = 'index';
	public $layout="main";
 	
	public function actions()
	{
		return array(
			// captcha action renders the CAPTCHA image displayed on the contact page
			'captcha'=>array(
				'class'=>'CCaptchaAction',
				'backColor'=>0xFFFFFF,
			),
			// page action renders "static" pages stored under 'protected/views/site/pages'
			// They can be accessed via: index.php?r=site/page&view=FileName
			'page'=>array(
				'class'=>'CViewAction',
			),
		);
	}

	/**
	 * This is the default 'index' action that is invoked
	 * when an action is not explicitly requested by users.
	 */
	public function actionGetStates()
	{
		 if (!empty($_GET['term'])) 
		 {
		 	$arrFinal = array();
		 	$qterm = '%'.$_GET['term'].'%';
			$objStateList = State::getList('STATE-LIST-LIKE', array('qterm'=>$qterm));
			$i = 0;
			foreach ($objStateList as $key=>$value) {
				$arrFinal[$i]['id'] = $key;
				$arrFinal[$i]['value'] = $value;
				$i++;
			}
			echo CJSON::encode($arrFinal); exit;
		  } 
		  else 
		  {
			return false;
		  }
    }
	public function actionGetCities()
	{
		 if (!empty($_GET['term'])) 
		 {
		 	$arrFinal = array();
		 	$qterm = '%'.$_GET['term'].'%';
		 	if (!empty($_GET['state'])) 
		 	$state = $_GET['state'];
		 	else
		 	$state = "";
		 	
			$objCityList = City::getList('CITY-LIST-LIKE', array('qterm'=>$qterm,'stateID'=>$state));
			$i = 0;
			foreach ($objCityList as $key=>$value) {
				$arrFinal[$i]['id'] = $key;
				$arrFinal[$i]['value'] = $value;
				$i++;
			}
			echo CJSON::encode($arrFinal); exit;
		  } 
		  else 
		  {
			return false;
		  }
    }
	public function actionSearchValueCities()
	{ 
		$cityID = "";
		//this function is using by business and propertydetails controller for suburb listing by seleting city
		 	if(Yii::app()->request->isAjaxRequest)
                {
                	if (isset($_GET['stateID']))
                	$_POST['Vendor']['vendor_stateID'] = $_GET['stateID'];
                	if (isset($_GET['cityID']))
                	$cityID = $_GET['cityID'];
                	
                }
		if(isset($_POST['Vendor']['vendor_stateID']))
		{ 
			$Term = $_POST['Vendor']['vendor_stateID'];
			$case = "BY-STATE-ID";
			$prompt = "Select City";
		
			$arrParam['stateID'] = isset($Term)?$Term:null ;
			$data = City::getList($case,$arrParam);
				
		       $data = CHtml::listData($data,'cityID','city_name');
						    
		       echo CHtml::tag('option',array('value'=>''),$prompt,true);
			   foreach($data as $value=>$name)
			   {
			   		if($cityID == $value)
			    	echo CHtml::tag('option',array('value'=>$value,'selected'=>'selected'),CHtml::encode($name));
			    	else 
			    	echo CHtml::tag('option',array('value'=>$value),CHtml::encode($name));
			   }	
		} 
		   Yii::app()->end();
	}
		
}